<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/js/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
	$(function() {
		$("button").click(
						function() {
							var book_id = $(this).parent().prev().prev().prev()
									.prev().text();
							$.ajax({
										type : "POST",
										url : "${pageContext.request.contextPath}/appointmentController/appoint.do",
										data : {
											"book_id" : book_id
										},
										async : false,
										cache : false,
										success : function(data) {
											if (data == "default") {
												alert("预约失败");
											} else {
												alert("预约成功");
												window.location.reload();
											}

										},
										error : function() {
											alert("系统错误");
										}
									});
						});
		
		$("#HPage").click(function(){
			window.location.href = "${pageContext.request.contextPath}/bookController/showBook.do?start=0";
		});
		$("#PPage").click(function(){
			var pg = ${page.start-page.count};
			if(pg>=0){
				window.location.href = "${pageContext.request.contextPath}/bookController/showBook.do?start="+pg;
			}
			else{
				window.location.reload();
			}
		});
		$("#NPage").click(function(){
			var pg = ${page.start+page.count};
			if(pg<=${page.count}){
				window.location.href = "${pageContext.request.contextPath}/bookController/showBook.do?start="+pg;
			}else{
				window.location.reload();
			}
		});
		$("#LPage").click(function(){
			window.location.href = "${pageContext.request.contextPath}/bookController/showBook.do?start="+${page.last};
		});
		
	});
	function exit(){
		var exit = confirm("是否退出登录?");
		if(exit == true){
			window.location.href = "${pageContext.request.contextPath}/loginController/exit.do";
		}else{
			
		}
	}
</script>
<title>show books</title>
<style type="text/css">
table {
	height: 50px;
	width: 800px;
	border: 1px solid red;
	font-size: 14px;
	text-align: center;
}

tr,td {
	border: 1px solid red;
}
</style>
</head>
<body>
	<a href=${pageContext.request.contextPath}/appointmentController/appointmentDetail.do>我的预约</a>
	<input type="button" onclick="exit()" value="退出登录">
	</br></br></br>
	<table>
		<tr>
			<td style="width: 10px;">id</td>
			<td style="width: 30px;">书名</td>
			<td style="width: 100px;">书籍简介</td>
			<td style="width: 50px;">剩余数量</td>
			<td style="width: 10px;"></td>
		</tr>
		<c:forEach var="item" items="${bookList}">
			<tr>
				<td id="${item.book_id }" style="width: 10px;">${item.book_id }</td>
				<td id="${item.book_name }" style="width: 30px;">${item.book_name }</td>
				<td id="${item.introd }" style="width: 100px;">${item.introd }</td>
				<td id="${item.quantity }" style="width: 50px;">${item.quantity }</td>
				<td style="width: 10px;"><button>预约</button></td>
			</tr>
		</c:forEach>
	</table>
	<div style="text-align:center">
        <input type="button" id="HPage" value="首    页"></input>
        <input type="button" id="PPage" value="上一页"></input>
        <input type="button" id="NPage" value="下一页"></input>
        <input type="button" id="LPage" value="末    页"></input>
    </div>
</body>
</html>
